<template>
  <div class="note">
    <el-table
      :data="noteList"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="title"
        label="标题"
        width="180">
      </el-table-column>
      <el-table-column
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
           type="primary"
           icon="el-icon-edit"
           circle
           @click="$router.push(`/admin/noteContent/${scope.row.id}`)"
          >
          </el-button>
          <el-button
           type="danger"
           icon="el-icon-delete"
           circle
           @click="openDelete(scope.row.id)"
           ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getNoteList, deleteNote } from '@/api/note'
export default {
  name: 'Note',
  data () {
    return {
      noteList: []
    }
  },
  created () {
    this.LoadNoteList()
  },
  methods: {
    async LoadNoteList () {
      const { data: res } = await getNoteList()
      this.noteList = res.data.noteList
    },
    openDelete (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const { data: res } = await deleteNote(id)
        if (res.code === 20000) {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.LoadNoteList()
        } else {
          this.$message.error(res.error)
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>
